import { Router, json } from 'express';
import { ApiResponse } from '@src/interface';
import { EmployeeService } from '@src/service';
import { expressMiddleware } from '@apollo/server/express4';
import cors from 'cors';
import { ApolloServers } from '@src/apollo';

export function getAdminRouter() {
    const adminRouter = Router();

    adminRouter.post('/add_employee', (req, res, next) => {
        console.log(req.body)
        EmployeeService.add(req.body).then(() => {
            res.send(<ApiResponse>{
                errcode: 0
            })
        }).catch(next)
    });
    adminRouter.use(
        '/graphql',
        cors(),
        json(),
        expressMiddleware(ApolloServers.instance.adminApolloServer),
    );
    return adminRouter
}